<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>上传</title>
</head>
<body>
<div style="margin: 100px;width: auto">
    <input type="file" id="icon">
</div>
</body>
<script type="text/javascript" src="jquery-2.1.4.min.js"></script>
<script type="text/javascript" src="layer/layer.js"></script>
<script type="text/javascript" src="royui.js"></script>
<script type="text/javascript">
    $(function () {
        let r = new royui()
        r.upload({
            elem: '#icon',
            auto: false,
            fileType: '*.jpg,gif,.png',
            buttonText: '选择文件',
            multi: true,
            limit: 3,
            fileSizeLimit: '50m',
            uploadScript: 'http://admin.yunduan.cn/upload/index',
            onUploadComplete: function ($data) {
                if ($data.code === 200) {
                    layer.msg($data.message, {icon: 6, time: 1000})
                } else {
                    layer.msg($data.message, {icon: 2, time: 1000});
                }
            },
            onError: function ($err) {
                console.log($err)
            }
        })
    })
</script>
</html>
